# 01网页的基础操作
from selenium import webdriver
import time
from selenium.webdriver.common.by import By

# driver = webdriver.Chrome()
# driver.get('https://www.baidu.com')
#
# time.sleep(3)
# driver.quit()


# 面向对象第一个测试案例重敲
# class Use_baidu():
#
#     def __init__(self):
#         self.driver=webdriver.Chrome()
#         self.driver.get('https://www.baidu.com')
#
#     def search_python(self):
#         self.driver.find_element(By.ID,'kw').send_keys('python自动化测试')
#         self.driver.find_element(By.ID,'su').click()
#         time.sleep(3)
#         print(self.driver.title)
#         if 'python' in self.driver.title:
#             print('找到了')
#         else:
#             print('没找到')
#
#     def quit(self):
#         time.sleep(3)
#         self.driver.quit()
#
#
# a = Use_baidu()
# a.search_python()
# a.quit()


# 模拟移动端重敲
# mobileEmulation={"deviceName":"iPhone XR"}
# options = webdriver.ChromeOptions()
# options.add_experimental_option("mobileEmulation",mobileEmulation)
#
# driver = webdriver.Chrome(options=options)
# driver.get('https://www.baidu.com')
# time.sleep(3)
# driver.quit()

# 无头模式
# options = webdriver.ChromeOptions()
# options.add_argument('-headless')
# driver = webdriver.Chrome(options=options)
# driver.get('https://www.baidu.com')
# print('打开了')
# driver.quit()

# 浏览器的操作
class Browser_operate:

    def __init__(self):
        self.driver= webdriver.Chrome()
        self.driver.get('https://www.baidu.com')

    def window_size(self):
        for i in range(3):
            time.sleep(2)
            self.driver.set_window_size(500,600)
            time.sleep(2)
            self.driver.maximize_window()
            time.sleep(2)
            self.driver.minimize_window()

    def forwad_back(self):
        for i in range(3):
            time.sleep(2)
            self.driver.forward()
            time.sleep(2)
            self.driver.back()

    def refresh(self):
        self.driver.refresh()

    def close(self):
        self.driver.find_element(By.LINK_TEXT,'新闻').click()
        time.sleep(3)
        self.driver.close()

    def quit(self):
        self.driver.quit()




if __name__ =='__main__':
    bo = Browser_operate()
    # bo.window_size()
    # bo.forwad_back()
    # bo.close()
    # bo.refresh()
    # bo.quit()
